草庐IT

java - 在测试中模拟 CompletionException

全部标签

javascript - 使用 Jasmine 测试 Angular2/TypeScript 管道

我有一个带有TypeScript应用程序设置的Angular2,带有非常基本的Jasmine测试。我想测试我的一根pipe。lpad.pipe.tsimport{Pipe,PipeTransform}from'@angular/core';@Pipe({name:'lpad'})exportclassLPadPipeimplementsPipeTransform{transform(value:any,args:string[]):any{letpad=args[0];return(pad+value).slice(-pad.length);}}在html模板中的用法:{{size.S

javascript - 使用 Jest 模拟请求 header 模块

functioncreateRequest(method){constinit={method,headers:newHeaders({.....}),};returnnewRequest(url,init);}我在上面的代码(https://davidwalsh.name/fetch)中使用请求header(带Fetch)然而,在使用Jest编写单元测试用例时,它给了我这个错误:ReferenceError:Headersisnotdefined我是否需要模拟这些标准模块?单元测试用例中如何导入Headers 最佳答案 我说是的,

javascript - 开 Jest 模拟默认导出 - 需要与导入

我在这里看到了一些关于用jest模拟默认导出的问题,但我认为还没有人问过这个问题:当模拟正在测试的模块的依赖项的默认导出时,如果模块使用ES6导入语句导入依赖项,测试套件将无法运行,声明TypeError:(0,_dependency.default)不是函数但是,如果模块改用require().default调用,它会成功。在我的理解中,importmodulefromlocation直接转换为constmodule=require(location).default,所以我很困惑为什么会这样。我宁愿保持我的代码风格一致,也不使用原始模块中的require调用。有办法吗?模拟测试文件

javascript - 使用 Visual Studio 的 JavaScript IntelliSense 模拟转换

我通过如下所示的数组将jQuery对象从另一个文件传递到函数中:$(document).bind("loadStoreDisplayCallGoals",function(source,urlParams){varselectedStoreDocument=urlParams["storeDocument"];}selectedStoreDocument应该是一个jQuery对象,但是VisualStudioIntellisense永远不会这样识别它。我尝试使用$.extend添加扩展selectedStoreDocument://castselectedStoreDocumentto

javascript - 如何使用 PhantomJS 测试网页是否返回 404/500?

我是PhantomJS和Javascript的新手,我正在编写一个测试加载时间的脚本,我想让它检测在测试它时是否遇到错误404/500,并在控制台日志。代码是这样的:varpage=require('webpage').create(),t,address;t=Date.now();vartestArray=['someURL'];functionloadTest(testURL){address=testURL;page.open(address,function(status){if(status!=='success'){console.log('FAILtoloadtheadd

javascript - 使用 jasmine 测试 javascript UI 的最佳方法

关闭。这个问题需要更多focused.它目前不接受答案。想改进这个问题吗?更新问题,使其只关注一个问题editingthispost.关闭4年前。Improvethisquestion我初看jasmine框架,它看起来很有前途,但我找不到使用dom的简单方法。我的意思是,模拟用户交互,比如完成和输入,点击一个按钮,然后检查dom是否正确更新,比如在输入验证后显示错误,并显示修改后的数据。就是您通常使用selenium等工具执行的操作。有没有标准的方法来做,或者ui测试超出了jasmine的领域,我应该为这样的任务寻找另一个框架?

javascript - 我们如何在 Angular 2 中编写基本单元测试?

我在官方网站上有以下Angular文档。但是在文档中测试部分已经过时并且不能使用当前的Angular2beta版本。我需要编写一个基本测试来检查if条件是否正常工作。我怎样才能在Angular2中使用jasmine来做到这一点。 最佳答案 设置jasmine以使用angular2(beta.7)运行typescript单元测试:设置Angular项目(参见说明5分钟快速入门https://angular.io/guide/quickstart)根目录是我的项目使用mpm安装jasminenpminstalljasmine-core-

javascript - 如何使用 Jest 和 Enzyme 在 React 中测试表单提交?无法读取未定义的属性 'preventDefault'

我正在编写一个测试来检查如果提交的登录表单没有数据,是否会显示错误通知组件。describe('Usersignin',()=>{it('shouldfailifnocredentialsareprovided',()=>{constloginComponent=shallow();expect(loginComponent.find('.form-login').length).toBe(1);loginComponent.find('.form-login').simulate('submit');expect(loginComponent.find(Notification).l

javascript - 测试 JavaScript 数组中是否存在 JSON 值

我有一个像这样的JSON对象数组:varmyArray=[{name:'foo',number:2},{name:'bar',number:9},{etc.}]如何检测myArray是否包含名称为“foo”的对象? 最佳答案 除非我遗漏了什么,否则您至少应该使用每一个以提高可读性而不是map。为了提高性能,您应该在找到所需内容后打破each,没有理由继续循环:varhasFoo=false;$.each(myArray,function(i,obj){if(obj.name==='foo'){hasFoo=true;returnfa

javascript - 在测试使用 qunit 显示的方法时避免/捕获/验证 Javascript 警报

我刚开始使用Qunit,想知道是否有办法捕获/验证/忽略警报,例如:functionto_test(){alert("I'mdisplayinganalert");return42;}然后有类似的东西:test("to_test",function(){//inthiscaseI'dliketotestthealert.alerts("I'mdisplayinganalert",to_test(),"to_test()shoulddisplayanalert");equals(42,to_test(),"to_test()shouldreturn42");//inthiscaseI'd